package com.sbdo.config;

import com.alibaba.dubbo.config.*;
import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableDubbo(scanBasePackages = "com.sbdo")
public class ProviderBConfig {


    /**
     *   <dubbo:application name="gmall-user-provider" />
     */
    @Bean
    public ApplicationConfig applicationConfig(){
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("prodiver-b");
        return applicationConfig;
    }

    /**
     * providerconfig
     */
    @Bean
    public ProviderConfig providerConfig(){
        ProviderConfig providerConfig = new ProviderConfig();
        providerConfig.setWait(3000);
        providerConfig.setPayload(128 * 1024 * 1024);
        providerConfig.setThreads(400);

        return providerConfig;
    }

    /**
     * 推荐在provider上尽量多配置consumer端属性，consumer会使用provider配置的值作为缺省值
     */
//    @Bean
//    public ConsumerConfig consumerConfig(){
//        ConsumerConfig consumerConfig = new ConsumerConfig();
//        consumerConfig.setTimeout(20000);
//        consumerConfig.setCheck(false);
//        consumerConfig.setRetries(0);
//
//        return consumerConfig;
//    }

    /**
     * <dubbo:registry address="zookeeper://106.15.176.xxx:2181?backup=106.15.176.xxx:2182,106.15.176.xxx:2183" />
     */
    @Bean
    public RegistryConfig registryConfig(){
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setProtocol("zookeeper");
        registryConfig.setAddress("127.0.0.1:2181");

        return registryConfig;
    }

    /**
     * <dubbo:protocol name="dubbo" port="20880" />
     */
    @Bean
    public ProtocolConfig protocolConfig(){
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setPort(20881);
        protocolConfig.setName("dubbo");
        protocolConfig.setThreads(100);

        return protocolConfig;
    }
}